package com.jyu.hakkatranslation.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jyu.hakkatranslation.dao.WordEntryMapper;
import com.jyu.hakkatranslation.pojo.WordEntry;
import com.jyu.hakkatranslation.service.SearchService;
import com.jyu.hakkatranslation.vo.EntryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class SearchServiceImpl extends ServiceImpl<WordEntryMapper, WordEntry> implements SearchService {
    @Autowired
    WordEntryMapper wordEntryMapper;
    /*根据关键词或地区查询*/
    @Override
    public List<WordEntry> searchWordEntry(EntryVo entryVo) {
        String place = entryVo.getPlace();
        String word = entryVo.getWord();
        List<WordEntry> list;
        /*根据关键词查询全部或地区查询*/
        if ("all".equals(place)){
            list = wordEntryMapper.selectList(
                    new QueryWrapper<WordEntry>()
                            .like("mandarin", word)
            );
        }else {
            list = wordEntryMapper.selectList(
                    new QueryWrapper<WordEntry>()
                            .like("mandarin", word)
                            .eq("place", place)
            );
        }
        return list;
    }
}
